package com.atguigu.tingshu.account.service.impl;

import com.atguigu.tingshu.account.mapper.UserAccountDetailMapper;
import com.atguigu.tingshu.account.service.UserAccountDetailService;
import com.atguigu.tingshu.model.account.UserAccountDetail;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.client.OrderInfoFeignClient;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserAccountDetailServiceImpl extends ServiceImpl<UserAccountDetailMapper, UserAccountDetail> implements UserAccountDetailService {

	@Autowired
	private UserAccountDetailMapper userAccountDetailMapper;
	@Autowired
	private OrderInfoFeignClient orderInfoFeignClient;
	/**
	 * 新增用户账户明细
	 * @param orderNo
	 */
	@Override
	public void addUserAccountDetail(String orderNo) {
		OrderInfo orderInfo =
				orderInfoFeignClient.getOrderInfo(orderNo);
		// 初始化DO
		UserAccountDetail userAccountDetail = new UserAccountDetail();
		userAccountDetail.setUserId(orderInfo.getUserId());
		userAccountDetail.setTitle(orderInfo.getOrderTitle());
		userAccountDetail.setTradeType("1204");
		userAccountDetail.setAmount(orderInfo.getDerateAmount());
		userAccountDetail.setOrderNo(orderNo);
		userAccountDetailMapper.insert(userAccountDetail);
	}
}
